package com.qwc.blog.controller.front;

import com.qwc.blog.service.ICategoryService;
import com.qwc.blog.service.IConfigService;
import com.qwc.blog.service.IPostsService;
import com.qwc.blog.service.ITagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

import static com.qwc.blog.common.constant.ResponseConstant.*;

/**
 * @author qiuwencong
 * @Date 2021/11/11 10:02
 * @Package com.qwc.blog.controller.front
 * @Description
 */
@RestController
@RequestMapping("/qblog")
public class IndexController {

    @Autowired
    private IConfigService configService;

    @Autowired
    private IPostsService postsService;

    @Autowired
    private ICategoryService categoryService;

    @Autowired
    private ITagService tagService;

    @RequestMapping("/index")
    public ResponseEntity<Object> index() {
        Map<String, Object> map = new HashMap<>(8);
        map.put(DATA, configService.getFrontConfig());
        map.put(BLOG_LIST, postsService.getNewBlogList());
        map.put(CATEGORIES, categoryService.selectMainCategoryList());
        map.put(TAGS, tagService.list());
        map.put(HOT_BLOG, postsService.getHotBlogList());
        return ResponseEntity.ok(map);
    }
}
